package org.will.demo.events;

import org.reveno.atp.api.EventsManager;
import org.reveno.atp.api.Reveno;
import org.will.cqrs.event.IEvent;
import org.will.ddd.eventing.DomainEvent;
import org.will.demo.view.MQDemoView;

/**
 * Created by EdifierWill on 2016/8/10.
 */
public class MQDemoUpdateEvent extends DomainEvent<Long> implements IEvent {

    public MQDemoUpdateEvent(long id) {
        this.setAggregateRootId(id);
        //System.out.println("MQDemoUpdateEvent:" + this.getAggregateRootId());
    }

    public void eventHandler(Reveno reveno,EventsManager.EventMetadata m) {
        if (!m.isRestore()) {
            MQDemoView mqDemoView = reveno.query().find(MQDemoView.class, this.getAggregateRootId());
            System.out.println("MQDemoUpdateEvent:" + mqDemoView._ename);
            RestApiClient client = new RestApiClient();
            client.update(mqDemoView);
        }
    }
}
